package vn.edu.saigontech.ncms.web.receipt;

import vn.edu.saigontech.ncms.model.info.ReceiptRefund;
import vn.edu.saigontech.ncms.service.ReceiptRefundService;
import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateReceiptRefundAction extends AbstractValidator {
	
	private Long id;
	private Long receiptId;
	private String date;
	private String fee;

	@Override
	public String check() {
		ReceiptRefund refund = ReceiptRefundService.INSTANCE.findByReceiptId(this.receiptId);
		if(Checker.isNull(this.id)) {
			if(!Checker.isNull(refund)) {
				this.sendKeyError("validator.exist", "refund");
			}
		}
		if(Checker.isEmpty(date)) {
			this.sendKeyError("validator.required", "date");
		}
		if(!Checker.isDate(this.date, this.i18n("format.date"))) {
			this.sendKeyError("validator.invalid", "date");
		}
		if(Checker.isEmpty(this.fee)) {
			this.sendKeyError("validator.required", "fee");
		}
		if(!Checker.isDouble(this.fee)) {
			this.sendKeyError("validator.invalid", "fee");
		}
		if(!Checker.isPositive(this.fee)) {
			this.sendKeyError("validator.invalid", "fee");
		}
		return this.toSuccess();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getFee() {
		return fee;
	}

	public void setFee(String fee) {
		this.fee = fee;
	}

	public Long getReceiptId() {
		return receiptId;
	}

	public void setReceiptId(Long receiptId) {
		this.receiptId = receiptId;
	}
}
